{extend name="base/base" /}
{block name="style"}
<style type="text/css">

</style>
{/block}
{block name="content"}
  <div class="layui-form-item layui-form-pane">
      <div class="layui-inline">
        <label class="layui-form-label">是否回复</label>
        <div class="layui-input-inline">
          <select class="layui-input" name='status' id='status'>
            <option value="">全部</option>
            <option value="1">已回</option>
            <option value="0">未回</option>
          </select>
        </div>
      </div>
      <div class="layui-inline">
          <label class="layui-form-label">用户ID</label>
          <div class="layui-input-inline">
              <input type="text" name="uid" autocomplete="off" class="layui-input" id='uid'>
          </div>
      </div>
      <div class="layui-inline">
          <label class="layui-form-label">用户名</label>
          <div class="layui-input-inline">
              <input type="text" name="username" autocomplete="off" class="layui-input" id='username'>
          </div>
      </div>
      <div class="layui-inline">
          <label class="layui-form-label">提问时间</label>
          <div class="layui-input-inline">
              <input type="text" class="layui-input" name="start_time" id="start_time" placeholder="yyyy-MM-dd">
          </div>
          <div class="layui-form-mid">-</div>
          <div class="layui-input-inline">
              <input type="text" class="layui-input" name="end_time" id="end_time" placeholder="yyyy-MM-dd">
          </div>
      </div>
      <div class="layui-inline">
        <div class="demoTable">
          <button class="layui-btn" data-type="reload">搜索</button>
        </div>
      </div>
  <table id="table" lay-filter="table"></table> 
    <script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">回复</a>
  </script>
</div>
{/block}
{block name="script"}
<script>
layui.use(['table', 'laydate'], function(){
  var table = layui.table;
  var laydate = layui.laydate;
  table.render({
    elem: '#table'
    ,height: 'full-200'
    ,url: '/admin/assist/dataList/' //数据接口
    ,limit:20
    ,page: true //开启分页
    ,id:'reload'
    ,cols: [[ //表头
      {field:'uid', title: '用户ID', width: 150}
      ,{field:'username', title: '用户名', width: 150}
      ,{field:'type', title: '问题类型', width: 150}
      ,{field:'content', title: '提问内容', width: 450}
      ,{field:'date', title: '提问时间', width: 200}
      ,{field:'answer', title: '回复内容', width: 450}
      ,{field:'rep_date', title: '回复时间', width: 200}
      ,{title: '是否回复', width: 100,templet: function(d){
        if(d.status == 1) {
          return '<span style="color:red">已回复</span>'
        }
        if(d.status == 0) {
          return '<span style="color:green">未回复</span>'
        }
      }}
      ,{title: '操作', width: 100,toolbar: '#barDemo'}
    ]]
  }); 
    // 搜索
  var $ = layui.$, active = {
        reload: function(){
            table.reload('reload', {
                where: {
                    status: $('#status').val(),
                    uid: $('#uid').val(),
                    username: $('#username').val(),
                    start_time: $('#start_time').val(),
                    end_time: $('#end_time').val()
                }
            });
        }
    };
    $('.demoTable .layui-btn').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
 //监听工具条
  table.on('tool(table)', function(obj){
    var data = obj.data;
    if(obj.event === 'edit'){
      layer.prompt({
      formType: 2,
        value: data.answer,
        title: '请输入回复内容'
      }, function(value,index){
        var post_data = {
          id:data.id,
          answer:value
        };
        $.ajax({
          url:'/admin/assist/reply',
          type:'POST',
          data:post_data,
          success:function(ret){
            if (ret.code == 0) {
              layer.msg('回复成功');
              window.location.reload();
            } else {
              layer.msg(ret.msg);
            }
          }
        }); 
      });
    }
  });
    //日期
  laydate.render({
    elem: '#start_time'
  });
  laydate.render({
    elem: '#end_time'
  });
});
</script>
{/block}
